//
//  SetTopView.m
//  YiXiProject
//
//  Created by iMac on 2019/7/23.
//  Copyright © 2019 iMac. All rights reserved.
//

#import "SetTopView.h"

@implementation SetTopView

-(UIView *)topView
{
    if(!_topView)
    {
        _topView = [[UIView alloc]init];
        _topView.backgroundColor = WhiteColor;
    }
    return _topView;
}

-(UIButton *)cancelButton
{
    if(!_cancelButton)
    {
        _cancelButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _cancelButton.tag = 100;
        [_cancelButton setTitle:@"Cancel" forState:UIControlStateNormal];
        [_cancelButton setTitleColor:ColorAlphe(65,105,225, 1) forState:UIControlStateNormal];
        _cancelButton.titleLabel.font = Font(19);
        [_cancelButton addTarget:self action:@selector(clickBtnTag:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _cancelButton;
}

-(UIButton *)loginOut
{
    if(!_loginOut)
    {
        _loginOut = [UIButton buttonWithType:UIButtonTypeCustom];
        _loginOut.tag = 101;
        [_loginOut setTitle:@"Logout" forState:UIControlStateNormal];
        [_loginOut setTitleColor:ColorAlphe(65,105,225, 1) forState:UIControlStateNormal];
        _loginOut.titleLabel.font = Font(19);
        [_loginOut addTarget:self action:@selector(clickBtnTag:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _loginOut;
}

-(UIButton *)saveButton
{
    if(!_saveButton)
    {
        _saveButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _saveButton.tag = 102;
        [_saveButton setTitle:@"Save" forState:UIControlStateNormal];
        [_saveButton setTitleColor:ColorAlphe(65,105,225, 1) forState:UIControlStateNormal];
        _saveButton.titleLabel.font = Font(19);
        [_saveButton addTarget:self action:@selector(clickBtnTag:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _saveButton;
}

-(UILabel *)settingTitle
{
    if(!_settingTitle)
    {
        _settingTitle = [[UILabel alloc] init];
        _settingTitle.text = @"Settings";
        _settingTitle.textColor = BlackColor;
        _settingTitle.font = [UIFont fontWithName:@"Arial-BoldMT" size:19];
        _settingTitle.hidden = YES;
    }
    return _settingTitle;
}

-(instancetype)initWithFrame:(CGRect)frame
{
    if(self = [super initWithFrame:frame])
    {
        [self addSubview:self.topView];
        [self.topView addSubview:self.cancelButton];
        [self.topView addSubview:self.loginOut];
        [self.topView addSubview:self.saveButton];
        [self.topView addSubview:self.settingTitle];
    }
    return self;
}

-(void)layoutSubviews
{
    [super layoutSubviews];
    
    _topView.sd_layout.leftSpaceToView(self, 0).bottomSpaceToView(self, 0).widthIs(SCREEN_WIDTH).heightIs(60);
    _cancelButton.sd_layout.leftSpaceToView(_topView, 15).bottomSpaceToView(_topView, 0).widthIs(60).heightIs(_topView.size.height);
    _saveButton.sd_layout.rightSpaceToView(_topView, 15).bottomSpaceToView(_topView, 0).widthIs(50).heightIs(_topView.size.height);
    _loginOut.sd_layout.rightSpaceToView(_saveButton, 10).bottomSpaceToView(_topView, 0).widthIs(60).heightIs(_topView.size.height);
    _settingTitle.sd_layout.leftSpaceToView(_topView, SCREEN_WIDTH/2-40).bottomSpaceToView(_topView, 0).widthIs(80).heightIs(_topView.size.height);
}


-(void)clickBtnTag:(UIButton *)butt
{
    if([_delegate respondsToSelector:@selector(clickButtonTag:)])
    {
        [_delegate clickButtonTag:butt.tag];
    }
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
